﻿using SaiLing.Domain.Specification;
using SaiLing.SingleSignOn.Domain.Entities.System;
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text;

namespace SaiLing.SingleSignOn.Domain.Specifications.System
{
    public class OrganizationMenuAuthoritySpecification : ISpecification<OrganizationMenuAuthority>
    {
        private Guid OrganizationId { get; set; }
        private Guid ModuleId { get; set; }
        private Guid ModuleActionId { get; set; }

        private Guid Appid { get; set; }

        public OrganizationMenuAuthoritySpecification(Guid? organizationId, Guid? moduleId, Guid? moduleActionId,Guid? appid)
        {
            OrganizationId = organizationId==null? Guid.Empty: organizationId.Value;
            ModuleId = moduleId == null ? Guid.Empty : moduleId.Value;
            ModuleActionId = moduleActionId == null ? Guid.Empty : moduleActionId.Value;
            Appid = appid == null ? Guid.Empty : appid.Value;
        }

        public Expression<Func<OrganizationMenuAuthority, bool>> SatisfiedBy()
        {
            Specification<OrganizationMenuAuthority> spec = new TrueSpecification<OrganizationMenuAuthority>();
          
            if (OrganizationId!=Guid.Empty)
                spec &= new DirectSpecification<OrganizationMenuAuthority>(x =>x.OrganizationId == OrganizationId);
            if (ModuleId != Guid.Empty)
                spec &= new DirectSpecification<OrganizationMenuAuthority>(x => x.ModuleId == ModuleId);
            if (ModuleActionId != Guid.Empty)
                spec &= new DirectSpecification<OrganizationMenuAuthority>(x => x.ModuleActionId == ModuleActionId);
            if (ModuleActionId != Guid.Empty)
                spec &= new DirectSpecification<OrganizationMenuAuthority>(x => x.ModuleActionId == ModuleActionId);
            if (Appid != Guid.Empty)
                spec &= new DirectSpecification<OrganizationMenuAuthority>(x => x.Appid == Appid);

            return spec.SatisfiedBy();
        }
    }
}
